package com.wgo.surveyModel.domain.common.impl;

import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
import java.util.Date;

import java.util.Set;

import com.wgo.surveyModel.domain.common.*;

public class StreamerSectionImpl extends EquipmentImpl implements StreamerSection
{
	private Integer lenght;
	private String type;
	private Streamer streamer;
	private Set<Hydrophone> hydrophones;
	private Set<IRMA> irmas;

	public StreamerSectionImpl(){
		super();
		hydrophones = new HashSet<Hydrophone>();
		irmas = new HashSet<IRMA>();
   
	}
	public Streamer getStreamer ()
	{
		return streamer;
	}

	public void setStreamer(Streamer streamer)
	{	
	     if( null != streamer)
	     { 	
		    this.streamer = streamer;
         	
		   //streamer.addSection(this);
		 }
		 else if( null != this.streamer)
		 {
		    this.streamer.removeSection(this);	
		    this.streamer = null;		      
		 }
		     	
	}

	public Set<Hydrophone> getHydrophones ()
	{
		return hydrophones;
	}
  
	public void setHydrophones(Set<Hydrophone> hydrophones)
	{
		this.hydrophones = hydrophones;
			
	}
	
  
	public boolean addHydrophone(Hydrophone hydrophone)
	{
	    if (!hydrophones.contains(hydrophone))
	    {
			this.hydrophones.add(hydrophone);   
		    if( this != hydrophone.getSection())
		    {
		      hydrophone.setSection(this);
		    }		  
		    
		}
		
		return true; 
	}
  
	public boolean removeHydrophone(Hydrophone hydrophone)
	{
		this.hydrophones.remove(hydrophone); 
			((HydrophoneImpl)hydrophone).setSection(null);
			
		
		return true;	
	}
	
	public Set<IRMA> getIrmas ()
	{
		return irmas;
	}
  
	public void setIrmas(Set<IRMA> irmas)
	{
		this.irmas = irmas;
			
	}
	
  
	public boolean addIrma(IRMA irma)
	{
	    if (!irmas.contains(irma))
	    {
			this.irmas.add(irma);   
		    if( this != irma.getSection())
		    {
		      irma.setSection(this);
		    }		  
		    
		}
		
		return true; 
	}
  
	public boolean removeIrma(IRMA irma)
	{
		this.irmas.remove(irma); 
			((IRMAImpl)irma).setSection(null);
			
		
		return true;	
	}
	
	public Integer getLenght ()
	{
		return lenght;
	}

	public void setLenght(Integer lenght)
	{	  	
		this.lenght = lenght;		
	}

	public String getType ()
	{
		return type;
	}

	public void setType(String type)
	{	  	
		this.type = type;		
	}

	public Double myOperation(Boolean param0)
    {
       
        Class clazz;
        try
        {
            String name = getClass().getSimpleName();
            String packageName = this.getClass().getPackage().getName();
            if(name.endsWith("Ejb"))
            {
                name = name.substring(0,name.length()-3) + "ImplUser";
                packageName = this.getClass().getSuperclass().getPackage().getName();
            }
            else
                name += "User";
           
            String className = packageName + "." + name;

            clazz = Class.forName(className); 
                                  
            Method method = clazz.getMethod("myOperation", Boolean.class);
                       
            Object[] args = new Object[1];
            args[0] = param0;
            return (Double)method.invoke(clazz.newInstance(), args);
		} 
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
	}
    
}
